package cn.zhiwen.util;

import cn.zhiwen.entity.BaseResponseModel;
import cn.zhiwen.enumname.RespMsgEnum;

/**
 * Created by lusue on 2017/8/7.
 */
public class ResultUtil {

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static BaseResponseModel setSuccess(Object repData) {
        BaseResponseModel baseResponseModel = new BaseResponseModel<>();
        baseResponseModel.setRepData(repData);
        baseResponseModel.setRepCode(RespMsgEnum.SUCCESS.getCode());
        baseResponseModel.setRepMsg(RespMsgEnum.SUCCESS.getMsg());
        baseResponseModel.setSuccess(true);
        return baseResponseModel;
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static void setSuccess(BaseResponseModel baseResponseModel, Object repData) {
        baseResponseModel.setRepData(repData);
        baseResponseModel.setRepCode(RespMsgEnum.SUCCESS.getCode());
        baseResponseModel.setRepMsg(RespMsgEnum.SUCCESS.getMsg());
        baseResponseModel.setSuccess(true);
    }

    public static BaseResponseModel setError(RespMsgEnum msgEnum) {
        return setError(msgEnum.getCode(), msgEnum.getMsg());
    }

    public static BaseResponseModel setError(String code, String msg) {
        BaseResponseModel baseResponseModel = new BaseResponseModel<>();
        baseResponseModel.setRepCode(code);
        baseResponseModel.setRepMsg(msg);
        baseResponseModel.setSuccess(false);
        return baseResponseModel;
    }
}
